<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/plugins/layui/css/layui.css}">
</head>
<body>
<div>
    <div class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">班级名称</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" id="className" name="className" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">所属年级</label>
                <div class="layui-input-inline layui-input-wrap">
                    <select id="gradeId" name="gradeId" th:with="grades=${@deptService.getDeptList()}">
                        <option value="">请选择</option>
                        <option th:each="dept : ${depts}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-inline layui-input-wrap" th:with="roles=${@roleService.list()}">
                    <input type="checkbox"  lay-filter="demo-checkbox-submit" th:each="role : ${roles}" th:value="${role.roleId}" th:title="${role.roleName}" lay-skin="primary">

                </div>
            </div>
        </div>
    </div>

    <button>
        <span class="layui-btn" id="save">保存</span>
    </button>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/plugins/layui/layui.js}"></script>
<script>
    // 异步请求加载部门列表
    layui.use(function (){
        var form = layui.form;
        var laydate = layui.laydate;
        var $ = layui.$;
        var layer = layui.layer;
        laydate.render({
            elem: '#birthday',
            type: 'date'
        });

        $("#save").click(function () {
            form.on('checkbox(demo-checkbox-filter)', function(data){
                var elem = data.elem; // 获得 checkbox 原始 DOM 对象
                var checked = elem.checked; // 获得 checkbox 选中状态
                var value = elem.value; // 获得 checkbox 值
                var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象

                layer.msg('checked 状态: '+ elem.checked);
            });
        })
    })

</script>
</body>
</html>